package com.cpecc.dao.wuzi;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cpecc.model.wuzi.BaoFei;
import com.cpecc.model.wuzi.FuJian;

@Repository
public class FuJianDao {

	@Resource
	private SessionFactory sessionFactory;
	
	public void save(FuJian fuJian){
		Session session=sessionFactory.getCurrentSession();
		session.save(fuJian);
		session.flush();
	}
	
	public FuJian get(String id){
		return (FuJian) sessionFactory.getCurrentSession().get(FuJian.class, id);
	}
	
	public boolean delete(String id){
		String hql="delete FuJian t where t.id=?";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, id);		
		return (query.executeUpdate() > 0);
	}
	
	@SuppressWarnings("unchecked")
	public List<FuJian> list(BaoFei baoFei){
		String hql="from FuJian t where t.baoFei=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, baoFei);
		return query.list();
	}
}
